package com.quartet.modules.equipment.service.impl;

import cn.hutool.core.bean.BeanUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.quartet.modules.equipment.dao.TEquipmentInfoDao;
import com.quartet.modules.equipment.dto.TEquipmentInfoAddRequestDto;
import com.quartet.modules.equipment.entity.TEquipmentInfo;
import com.quartet.modules.equipment.service.TEquipmentInfoService;
import com.quartet.utils.RandomUtils;
import org.springframework.stereotype.Service;
import org.springframework.util.ObjectUtils;

/**
 * 设备信息表(TEquipmentInfo)表服务实现类
 *
 * @author makejava
 * @since 2021-05-04 16:34:15
 */
@Service("tEquipmentInfoService")
public class TEquipmentInfoServiceImpl extends ServiceImpl<TEquipmentInfoDao, TEquipmentInfo> implements TEquipmentInfoService {

    /**
     * 添加设备信息
     *
     * @param tEquipmentInfoAddRequestDto
     */
    @Override
    public void addEquipmentInfo(TEquipmentInfoAddRequestDto tEquipmentInfoAddRequestDto) {
        if (!ObjectUtils.isEmpty(tEquipmentInfoAddRequestDto)) {
            TEquipmentInfo tEquipmentInfo = BeanUtil.copyProperties(tEquipmentInfoAddRequestDto, TEquipmentInfo.class);
            tEquipmentInfo.setEquipmentCode(RandomUtils.getEquipmentCode());
            this.baseMapper.insert(tEquipmentInfo);
        }
    }

    /**
     * 功能描述: 修改设备信息
     *
     * @param tEquipmentInfoAddRequestDto
     * @return void
     * @author huipanxing huipanxing@chinasofti.com
     * @date 2021/5/13 16:19
     */
    @Override
    public void updateEquipmentInfo(TEquipmentInfoAddRequestDto tEquipmentInfoAddRequestDto) {
        if (!ObjectUtils.isEmpty(tEquipmentInfoAddRequestDto)) {
            TEquipmentInfo tEquipmentInfo = BeanUtil.copyProperties(tEquipmentInfoAddRequestDto, TEquipmentInfo.class);
            this.baseMapper.updateById(tEquipmentInfo);
        }
    }

    /**
     * 根据设备编码删除设备信息
     *
     * @param equipmentCode
     */
    @Override
    public void deleteEquipmentInfo(String equipmentCode) {
        this.baseMapper.delete(new QueryWrapper<TEquipmentInfo>().lambda().eq(TEquipmentInfo::getEquipmentCode, equipmentCode));
    }

    /**
     * 根据设备编码查询设备信息
     *
     * @param equipmentCode
     * @return
     */
    @Override
    public TEquipmentInfoAddRequestDto selectEquipmentInfo(String equipmentCode) {
        TEquipmentInfo tEquipmentInfo = this.baseMapper.selectOne(new QueryWrapper<TEquipmentInfo>().lambda().eq(TEquipmentInfo::getEquipmentCode, equipmentCode));
        TEquipmentInfoAddRequestDto tEquipmentInfoAddRequestDto = BeanUtil.copyProperties(tEquipmentInfo, TEquipmentInfoAddRequestDto.class);
        return tEquipmentInfoAddRequestDto;
    }
}
